package com.svmc.app.task.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.svmc.app.task.activity.R;
import com.svmc.app.task.model.TaskModel;

public class ListAllTaskAdapter extends BaseAdapter{
	Context mcontext;
	ArrayList<TaskModel> listtask = new ArrayList<TaskModel>();
	private LayoutInflater mInflater;
	DbAdapter db;
    public ListAllTaskAdapter(Context context, ArrayList<TaskModel> tasks) {
    	mcontext = context;
    	listtask = tasks;
    	mInflater = LayoutInflater.from(context);
    	db = new DbAdapter(context);
    }
	@Override
	public int getCount() {
		
		return listtask.size();
	}

	@Override
	public Object getItem(int position) {
		
		return listtask.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolderListALl holder ;
		if(view ==null){
			mInflater = (LayoutInflater) mcontext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = mInflater.inflate(R.layout.item_task_all, null);
			holder = new ViewHolderListALl();
			holder.isReminder =(ImageView)view.findViewById(R.id.itemalltask_img_isreminder);
			holder.titleTask =(TextView)view.findViewById(R.id.itemalltask_txt_titletask);
			holder.timeFinish =(TextView)view.findViewById(R.id.itemalltask_txt_timefinish);
			holder.isFinish =(TextView)view.findViewById(R.id.itemalltask_txt_isfinish);
			holder.timeReminder=(TextView)view.findViewById(R.id.itemalltask_txt_timereminder);
			view.setTag(holder);
		}else {
			holder =(ViewHolderListALl)view.getTag();
		}
		holder.titleTask.setText(listtask.get(position).getTask());
		holder.timeFinish.setText(listtask.get(position).getTimefinish());
		// set status
		if(listtask.get(position).getStatus()==0){
			holder.isFinish.setText(mcontext.getString(R.string.item_all_task_not_finish));
		}else {
			holder.isFinish.setText(mcontext.getString(R.string.item_all_task_finished));
		}
		// set status reminder
		if(listtask.get(position).getIsreminder()==0){
			holder.isReminder.setImageResource(R.drawable.is_not_reminder);
			holder.timeReminder.setText("");
		}else {
			holder.isReminder.setImageResource(R.drawable.is_reminder);
			holder.timeReminder.setText(listtask.get(position).getTimereminder());
		}
		
		
		return view;
	}
	
	static class ViewHolderListALl {
		ImageView isReminder;
		TextView titleTask;
		TextView timeFinish;
		TextView isFinish;
		TextView timeReminder;
		
		
		
		
	}

	

}
